﻿using IServices;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
using System;
using System.Linq;
using YL.Core.Dto;
using YL.Core.Entity;
using YL.Core.Entity.Fluent.Validation;
using YL.NetCore.Attributes;
using YL.NetCore.NetCoreApp;
using YL.Utils.Extensions;
using YL.Utils.Pub;
using YL.Utils.Table;

namespace Method.SmartMeter.Controllers
{
    //设备状态查看及设备当前实时数据页面
    public class DeviceDataHistoryController : BaseController
    {
        private readonly IMeter_DeviceDataHistoryServices _DeviceDataHistoryServices;

        public DeviceDataHistoryController(IMeter_DeviceDataHistoryServices DeviceDataHistoryServices)
        {
            _DeviceDataHistoryServices = DeviceDataHistoryServices;
        }

        //设备状态查看
        [HttpGet]
        [CheckMenu]
        public IActionResult Index()
        {
            if (!string.IsNullOrEmpty(Request.Query["ClientId"]) && !string.IsNullOrEmpty(Request.Query["DeviceId"]))
            {
                ViewBag.ClientId = Convert.ToInt64(Request.Query["ClientId"]);
                ViewBag.DeviceId = Convert.ToInt64(Request.Query["DeviceId"]);
            }
            return View();
        }

        //设备当前实时数据
        [HttpPost]
        [OperationLog(LogType = LogType.select)]
        public ContentResult CurrentDetailsList([FromForm]Bootstrap.BootstrapParams bootstrap)
        {
            Int64 ClientId = Convert.ToInt64(Request.Query["ClientId"]);
            Int64 DeviceId = Convert.ToInt64(Request.Query["DeviceId"]);
            var sd = _DeviceDataHistoryServices.CurrentDetailsList(bootstrap, ClientId, DeviceId, UserDtoCache.UserId);
            return Content(sd);
        }

        //设备历史数据
        [HttpPost]
        [OperationLog(LogType = LogType.select)]
        public ContentResult HistoryDetailsList([FromForm]Bootstrap.BootstrapParams bootstrap)
        {
            Int64 ClientId = Convert.ToInt64(Request.Query["ClientId"]);
            Int64 DeviceId = Convert.ToInt64(Request.Query["DeviceId"]);
            var sd = _DeviceDataHistoryServices.HistoryDetailsList(bootstrap, ClientId, DeviceId, UserDtoCache.UserId);
            return Content(sd);
        }

        //监控记录查看
        [HttpGet]
        [CheckMenu]
        public IActionResult Monitor()
        {
            return View();
        }

        //设备历史数据
        [HttpPost]
        [OperationLog(LogType = LogType.select)]
        public ContentResult HistoryMonitorList([FromForm] Bootstrap.BootstrapParams bootstrap)
        {
            var sd = _DeviceDataHistoryServices.HistoryStationList(bootstrap, UserDtoCache.UserId);
            return Content(sd);
        }

    }
}